<template>
  <div class="index-news-box clearfix">
    <personService />
    <div class="box clearfix">
      <div class="location">
        <router-link to="/cooperation">{{$t('common.nav.cooperation')}}</router-link>
         > 
        {{leftData.nav[type].name}}
      </div>
      <div class="mainLR clearfix">
        <mainLes :leftData = 'leftData' @leftChange="leftChange" />
        <div class="main-right">
          <div class="news-ri-tit flex-lect">{{leftData.nav[type].name}}</div>
          <div class="news-list clearfix">
            
            <template v-if="type != 2">
              <router-link target="_blank" :to="url+type+'&id='+item.id" class="news-item flex-bect" v-for="(item, index) in newsList" :key="index">
                <h2 v-if="type == 2" class="font14 ntit">{{item.name}}</h2>
                <h2 v-else class="font14 ntit">{{item.title}}</h2>
                <span v-if="type != 2">{{item.createTime.substr(0,10)}}</span>
                <span v-if="type == 2">{{item.updateTime.substr(0,10)}}</span>
              </router-link>
            </template>
            <template v-else>
              <router-link target="_blank" :to="'/vip/c_recruit_company_detail?type=1'+'&id='+item.erId" class="news-item flex-bect" v-for="(item, index) in newsList" :key="index">
                <h2 v-if="type == 2" class="font14 ntit">{{item.name}}</h2>
                <h2 v-else class="font14 ntit">{{item.title}}</h2>
                <span v-if="type != 2">{{item.createTime.substr(0,10)}}</span>
                <span v-if="type == 2">{{item.updateTime.substr(0,10)}}</span>
              </router-link>
            </template>
          </div>
          <el-pagination class="tc"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageNo"
            :page-size="pageSize"
            layout="prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {ajax,showToast} from '@/utils/js.js'
import {proCooperationUnit,proEnterpriseWall} from '@/services/api.js'
import mainLes from '@/components/mainLe.vue'
import personService from '@/components/personService.vue'

const log = console.log
export default {
  components:{
    mainLes,
    personService
  },
  data() {
    return {
      newsList:[],
      type:0,
      url:'/cooperation_detail?list=0&type=',
      pageNo:1,
      pageSize:10,  
      total:0
    }
  },
  mounted(){
    log(this.$t('news.news'))
    let type = this.$route.query.type
    var list = this.leftData.type
    log('type',type)
    this.leftData.type = type
    this.type = type
    this.content(type)
    if(type == 2){
      this.url = 'vip/c_recruit_company_detail?type='
    } else {
      this.url = '/cooperation_detail?&type='
    }
  },
  computed:{
    leftData(){
      let data={
        type:0,
        tit:this.$t('common.nav.cooperation'),
        nav:[
          {name:this.$t('news.schooleHz'),id:0},
          {name:this.$t('news.companyHz'),id:1},
          {name:this.$t('news.joinCompany'),id:2}
        ]
      }
      return data
    },
  },
  watch:{
    '$i18n.locale'(){
      this.content()
    },
  },
  methods:{
	
    leftChange(e){
      this.type = e.id
      if(e.id == 2){
        this.url = 'vip/c_recruit_company_detail?type='
      } else {
		this.url = '/cooperation_detail?type='
		}
      this.pageNo = 1;
      this.content(e.id);
      log('this.type',this.type)
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      
    },
    handleCurrentChange(val) {
      console.log('当前页',val);
      this.content();
    },
    changeList(){
      this.content()
    },
    content(type = this.type){
		var data = {
			pageNo: this.pageNo,
			pageSize: this.pageSize
		}
		var func = ''
		if (type == 0) {
			data.cooperationCategary = 1 //1院校合作,2企业合作	
			data.cooperationUnit = ''
			
			func = proCooperationUnit
		} else if (type == 1) {
			data.cooperationCategary = 2 //1院校合作,2企业合作
			data.cooperationUnit = ''
			
			func = proCooperationUnit
		} else {
			func = proEnterpriseWall
		}
		
		ajax(this,func,data,res=>{
			this.newsList = res.data.records
			this.total = res.data.total;
		})
		/*
      let data={
        pageNo:this.pageNo,
        pageSize:this.pageSize
      }
      let url = ''
      if(type == 0){
        url = getNews
      }else if(type == 1){
        url = activityApply
      }
      ajax(this,getNews,data,res=>{
        this.newsList = res.data.records;
        this.total = res.data.total;
      },err=>{
        showToast(this,err.msg)
      })
	  */
    },
    //首页跳转
    indexLink(data){
     if(data.outLink && data.outLink==1){
        window.open(data.linkUrl,'-blank')
      }else{
        window.location.href = data.linkUrl
      }
    },
    
  }
}
</script>
<style lang="scss">
  
  .index-news-box{width:100%;background-color: #fff;
    .main-right{
      span{width:80px;text-align: right;} 
    }
  }
</style>